﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Autodesk.Revit.Creation;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Plumbing;
using YArchitech.LIB;

namespace YArchitech.Revit
{
	public class UnifiedModified
	{
		public static void ActivateFamilySymbol(FamilySymbol fs)
		{
			if (!fs.IsActive)
			{
				fs.Activate();
			}
		}

		public static SiteLocation GetSiteLocation(ProjectLocation proLocation)
		{
			return proLocation.SiteLocation;
		}

		public static TextNote HYCreatTextNote(Autodesk.Revit.DB.Document doc, string textFontName, string strTextNode, XYZ startPoint)
		{
			TextNoteType textNoteType = UnifiedModified.GetTextNoteType(doc, textFontName);
			textNoteType.GetParameter(BuiltInParameter.TEXT_BACKGROUND).Set(1);
			textNoteType.GetParameter(BuiltInParameter.TEXT_FONT).Set(textFontName);
			Autodesk.Revit.DB.View activeView = doc.ActiveView;
			TextNote textNote = doc.Create.NewTextNote(activeView, startPoint, new XYZ(1.0, 0.0, 0.0), new XYZ(0.0, 1.0, 0.0), 0.0, 1088, strTextNode);
			textNote.TextNoteType = textNoteType;
			return textNote;
		}

		public static TextNote HYCreatTextNote(Autodesk.Revit.DB.Document doc, string strTextNode, XYZ startPoint, TextNoteType textNoteType)
		{
			textNoteType.GetParameter(BuiltInParameter.TEXT_BACKGROUND).Set(1);
			Autodesk.Revit.DB.View activeView = doc.ActiveView;
			return TextNote.Create(doc, activeView.Id, startPoint, strTextNode, textNoteType.Id);
		}

		public static double GetTextNoteWidth(Autodesk.Revit.DB.Document doc, TextNote txtNote)
		{
			return txtNote.Width * (double)doc.ActiveView.Scale;
		}

		private static TextNoteType GetTextNoteType(Autodesk.Revit.DB.Document doc, string textNoteTypeName)
		{
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			filteredElementCollector.OfClass(typeof(TextNoteType));
			TextNoteType textNoteType = null;
			foreach (Element element in filteredElementCollector)
			{
				TextNoteType textNoteType2 = (TextNoteType)element;
				if (textNoteType2.Name.Contains(textNoteTypeName))
				{
					textNoteType = textNoteType2;
					break;
				}
			}
			if (textNoteType == null)
			{
				textNoteType = (filteredElementCollector.FirstElement() as TextNoteType);
			}
			return textNoteType;
		}

		public static DisplayUnitType GetDisplayUnitType(Autodesk.Revit.DB.Document doc, UnitType unitType)
		{
			return doc.GetUnits().GetFormatOptions(unitType).DisplayUnits;
		}

		public static string GetFormatOptionsName(Autodesk.Revit.DB.Document doc, UnitType unitType)
		{
			return doc.GetUnits().GetFormatOptions(unitType).ToString();
		}

		public static BoundingBoxXYZ GetFamilyInstanceBox(FamilyInstance fi)
		{
			return fi.get_Geometry(new Options
			{
				View = fi.Document.ActiveView,
				ComputeReferences = true
			}).GetBoundingBox();
		}

		public static IList<XYZ> GetPlanarFacePoints(PlanarFace pFace)
		{
			new List<XYZ>();
			return pFace.Triangulate().Vertices;
		}

		public static IList<Edge> GetPlanarFaceEdges(PlanarFace pFace)
		{
			IList<Edge> list = new List<Edge>();
			foreach (object obj in pFace.EdgeLoops)
			{
				foreach (object obj2 in ((EdgeArray)obj))
				{
					Edge item = (Edge)obj2;
					list.Add(item);
				}
			}
			return list;
		}

		public static IList<PlanarFace> GetFamilyInstanceSpecialSurface(Autodesk.Revit.DB.Document doc, FamilyInstance fi, bool beHandOrientation)
		{
			List<PlanarFace> list = new List<PlanarFace>();
			IEnumerable<PlanarFace> familyInstanceSurface = UnifiedModified.GetFamilyInstanceSurface(doc, fi);
			XYZ handOrientation = fi.HandOrientation;
			foreach (PlanarFace planarFace in familyInstanceSurface)
			{
				if (beHandOrientation)
				{
					XYZ xyz = planarFace.FaceNormal();
					if (xyz.IsAlmostEqualTo(handOrientation, 0.0001) || xyz.IsAlmostEqualTo(-1.0 * handOrientation, 0.0001))
					{
						list.Add(planarFace);
					}
				}
				else
				{
					list.Add(planarFace);
				}
			}
			return list;
		}

		public static XYZ GetPlanarFaceNormal(PlanarFace face)
		{
			XYZ zero = XYZ.Zero;
			if (null == face)
			{
				return zero;
			}
			return face.FaceNormal().Normalize();
		}

		public static IList<PlanarFace> GetFamilyInstanceSurface(Autodesk.Revit.DB.Document doc, FamilyInstance fi)
		{
			List<PlanarFace> list = new List<PlanarFace>();
			GeometryElement geometryElement = fi.get_Geometry(new Options
			{
				ComputeReferences = true,
				View = doc.ActiveView
			});
			List<GeometryObject> list2 = new List<GeometryObject>();
			foreach (GeometryObject item in geometryElement)
			{
				list2.Add(item);
			}
			for (int i = 0; i < list2.Count; i++)
			{
				GeometryObject geometryObject = list2[i];
				if (geometryObject is GeometryInstance)
				{
					UnifiedModified.GetFaces(geometryObject, ref list);
				}
				else if (geometryObject is Solid)
				{
					foreach (object obj in (geometryObject as Solid).Faces)
					{
						PlanarFace item2 = (PlanarFace)obj;
						list.Add(item2);
					}
				}
			}
			return list;
		}

		private static void GetFaces(object geoObject, ref List<PlanarFace> arFaces)
		{
			GeometryInstance geometryInstance = geoObject as GeometryInstance;
			List<GeometryObject> list = new List<GeometryObject>();
			foreach (GeometryObject item in geometryInstance.GetInstanceGeometry())
			{
				list.Add(item);
			}
			foreach (object obj in list)
			{
				if (obj is GeometryInstance)
				{
					UnifiedModified.GetFaces(obj, ref arFaces);
				}
				else if (obj is Solid)
				{
					foreach (object obj2 in (obj as Solid).Faces)
					{
						PlanarFace item2 = (PlanarFace)obj2;
						arFaces.Add(item2);
					}
				}
			}
		}

		public static IList<PlanarFace> GetDuctSurface(Duct duct)
		{
			IList<PlanarFace> list = new List<PlanarFace>();
			IEnumerator<GeometryObject> enumerator = duct.get_Geometry(new Options
			{
				View = duct.Document.ActiveView,
				ComputeReferences = true
			}).GetEnumerator();
			enumerator.Reset();
			while (enumerator.MoveNext())
			{
				GeometryObject geometryObject = enumerator.Current;
				if (geometryObject is Solid)
				{
					foreach (object obj in (geometryObject as Solid).Faces)
					{
						Face face = (Face)obj;
						if (face is PlanarFace)
						{
							list.Add(face as PlanarFace);
						}
					}
				}
			}
			return list;
		}

		public static IList<Edge> GetDuctEdges(Duct duct)
		{
			IList<Edge> list = new List<Edge>();
			IEnumerator<GeometryObject> enumerator = duct.get_Geometry(new Options
			{
				View = duct.Document.ActiveView,
				ComputeReferences = true
			}).GetEnumerator();
			enumerator.Reset();
			while (enumerator.MoveNext())
			{
				GeometryObject geometryObject = enumerator.Current;
				if (geometryObject is Solid)
				{
					foreach (object obj in (geometryObject as Solid).Edges)
					{
						Edge item = (Edge)obj;
						list.Add(item);
					}
				}
			}
			return list;
		}

		public static System.Drawing.Color GetElementFillColor(Autodesk.Revit.DB.View view, Element elem)
		{
			ICollection<ElementId> collection = new List<ElementId>();
			YJKElement hyelement = new YJKElement(elem);
			collection.Add(hyelement.GetYJKElementId());
			return null;
		}

		public static Reference GetReference(ReferencePlane refPlane)
		{
			return refPlane.GetReference();
		}

		public static List<double> GetDuctTerminalTagSize()
		{
			return new List<double>
			{
				200.0,
				600.0
			};
		}

		public static List<double> GetSystemDiagramDrawSize()
		{
			return new List<double>
			{
				0.0,
				0.0
			};
		}

		public static System.Drawing.Color GetElementProjectColor(Autodesk.Revit.DB.View view, Element elem)
		{
			ICollection<ElementId> collection = new List<ElementId>();
			YJKElement hyelement = new YJKElement(elem);
			collection.Add(hyelement.GetYJKElementId());
			return null;
		}

		public static void SetElementFillColor(Autodesk.Revit.DB.View view, Element elem, System.Drawing.Color color)
		{
			ICollection<ElementId> collection = new List<ElementId>();
			YJKElement hyelement = new YJKElement(elem);
			collection.Add(hyelement.GetYJKElementId());
		}

		public static double GetTextLength(bool withArea, bool withFloor)
		{
			double result = 1100.0;
			if (withArea && withFloor)
			{
				result = 1400.0;
			}
			else if (!withArea && withFloor)
			{
				result = 1100.0;
			}
			else if (withArea && !withFloor)
			{
				result = 1100.0;
			}
			else if (!withArea && !withFloor)
			{
				result = 800.0;
			}
			return result;
		}

		public static double GetTextXOffsetHori(bool withArea, bool withFloor)
		{
			double result = 550.0;
			if (withArea && withFloor)
			{
				result = 710.0;
			}
			else if (!withArea && withFloor)
			{
				result = 550.0;
			}
			else if (withArea && !withFloor)
			{
				result = 550.0;
			}
			else if (!withArea && !withFloor)
			{
				result = 400.0;
			}
			return result;
		}

		public static double GetTextYOffsetVert(bool withArea, bool withFloor)
		{
			double result = 540.0;
			if (withArea && withFloor)
			{
				result = 700.0;
			}
			else if (!withArea && withFloor)
			{
				result = 540.0;
			}
			else if (withArea && !withFloor)
			{
				result = 540.0;
			}
			else if (!withArea && !withFloor)
			{
				result = 400.0;
			}
			return result;
		}

		public static void SetElementProjectColor(Autodesk.Revit.DB.View view, Element elem, System.Drawing.Color color)
		{
			ICollection<ElementId> collection = new List<ElementId>();
			YJKElement hyelement = new YJKElement(elem);
			collection.Add(hyelement.GetYJKElementId());
		}

		public static BuiltInCategory GetAreaAreaSeparationLines()
		{
			return -2000066;
		}

		public static Curve GetBoundarySegmentCurve(BoundarySegment segment)
		{
			return segment.Curve;
		}

		public static Element GetBoundarySegmentElement(Autodesk.Revit.DB.Document doc, BoundarySegment segment)
		{
			return segment.Element;
		}

		public static ElementId GetBoundarySegmentLinkElementId(BoundarySegment segment)
		{
			return segment.LinkElementId;
		}

		public static ElementSet HYNewFamilyInstances(Autodesk.Revit.DB.Document doc, List<FamilyInstanceCreationData> dataList)
		{
			ElementSet elementSet = new ElementSet();
			foreach (ElementId elementId in doc.Create.NewFamilyInstances2(dataList).ToList<ElementId>())
			{
				if (null != elementId && elementId.IntegerValue != -1)
				{
					elementSet.Insert(doc.GetElementById(elementId));
				}
			}
			return elementSet;
		}

		private static void SetFitting(RoutingPreferenceManager rpm, RoutingPreferenceRuleGroupType rprg, FamilySymbol fs, string description)
		{
			for (int i = 0; i < rpm.GetNumberOfRules(rprg); i++)
			{
				if (fs.Id == rpm.GetRule(rprg, i).MEPPartId)
				{
					rpm.RemoveRule(rprg, i);
					break;
				}
			}
			rpm.AddRule(rprg, new RoutingPreferenceRule(fs.Id, description), 0);
		}

		private static bool CheckFittingName(RoutingPreferenceManager rpm, RoutingPreferenceRuleGroupType rprg, string fsName, Autodesk.Revit.DB.Document doc)
		{
			bool result = false;
			if ("" == fsName && rpm.GetNumberOfRules(rprg) > 0)
			{
				return true;
			}
			for (int i = 0; i < rpm.GetNumberOfRules(rprg); i++)
			{
				RoutingPreferenceRule rule = rpm.GetRule(rprg, i);
				if (rule != null && rpm.GetRule(rprg, i).MEPPartId.IntegerValue >= 0)
				{
					Element family = (doc.GetElementById(rpm.GetRule(rprg, i).MEPPartId) as FamilySymbol).Family;
					if (family == null)
					{
						result = false;
					}
					else if (family.Name == "HY_" + fsName)
					{
						rpm.RemoveRule(rprg, i);
						rpm.AddRule(rprg, rule, 0);
						result = true;
						break;
					}
				}
			}
			return result;
		}

		public static ICollection<MEPSize> GetAllMepSize(PipeType pipeType)
		{
			RoutingPreferenceRule rule = pipeType.RoutingPreferenceManager.GetRule((Autodesk.Revit.DB.RoutingPreferenceRuleGroupType)0, 0);
			return (pipeType.Document.GetElementById(rule.MEPPartId) as PipeSegment).GetSizes();
		}

		public static bool DeleteMepSize(PipeType pipeType, double nominalDiameter)
		{
			bool result = false;
			try
			{
				RoutingPreferenceRule rule = pipeType.RoutingPreferenceManager.GetRule((Autodesk.Revit.DB.RoutingPreferenceRuleGroupType)0, 0);
				PipeSegment pipeSegment = pipeType.Document.GetElementById(rule.MEPPartId) as PipeSegment;
				bool flag = false;
				IEnumerator<MEPSize> enumerator = pipeSegment.GetSizes().GetEnumerator();
				{
					while (enumerator.MoveNext())
					{
						if (Math.Abs(enumerator.Current.NominalDiameter - nominalDiameter) < 1E-06)
						{
							flag = true;
							break;
						}
					}
				}
				if (flag)
				{
					pipeSegment.RemoveSize(nominalDiameter);
				}
				result = true;
			}
			catch (Exception)
			{
				result = false;
				throw;
			}
			return result;
		}

		public static bool AddMepSize(PipeType pipeType, double nominalDiameter, double innerDiameter, double outDiameter)
		{
			bool result = false;
			try
			{
				RoutingPreferenceRule rule = pipeType.RoutingPreferenceManager.GetRule((Autodesk.Revit.DB.RoutingPreferenceRuleGroupType)0, 0);
				Segment segment = pipeType.Document.GetElementById(rule.MEPPartId) as PipeSegment;
				MEPSize mepsize = new MEPSize(nominalDiameter, innerDiameter, outDiameter, true, true);
				segment.AddSize(mepsize);
				result = true;
			}
			catch (Exception)
			{
				result = false;
				throw;
			}
			return result;
		}

		public static BuiltInCategory GetPipeSegments()
		{
			return -2008163;
		}

		public static void ClearSegmentFitting(PipeType pipeType, int num)
		{
			RoutingPreferenceManager routingPreferenceManager = pipeType.RoutingPreferenceManager;
			RoutingPreferenceRuleGroupType routingPreferenceRuleGroupType = -1;
			switch (num)
			{
			case 0:
				routingPreferenceRuleGroupType = 0;
				break;
			case 1:
				routingPreferenceRuleGroupType = 1;
				break;
			case 2:
				routingPreferenceRuleGroupType = 2;
				break;
			case 3:
				routingPreferenceRuleGroupType = 3;
				break;
			case 4:
				routingPreferenceRuleGroupType = 4;
				break;
			case 5:
				routingPreferenceRuleGroupType = 5;
				break;
			case 10:
				routingPreferenceRuleGroupType = 10;
				break;
			}
			if (routingPreferenceRuleGroupType != -1)
			{
				for (int i = routingPreferenceManager.GetNumberOfRules(routingPreferenceRuleGroupType) - 1; i >= 0; i--)
				{
					routingPreferenceManager.RemoveRule(routingPreferenceRuleGroupType, i);
				}
			}
		}

		public static IList<ElementId> GetSegmentFitting(PipeType pipeType, int num)
		{
			IList<ElementId> list = new List<ElementId>();
			RoutingPreferenceManager routingPreferenceManager = pipeType.RoutingPreferenceManager;
			RoutingPreferenceRuleGroupType routingPreferenceRuleGroupType = -1;
			switch (num)
			{
			case 0:
				routingPreferenceRuleGroupType = 0;
				break;
			case 1:
				routingPreferenceRuleGroupType = 1;
				break;
			case 2:
				routingPreferenceRuleGroupType = 2;
				break;
			case 3:
				routingPreferenceRuleGroupType = 3;
				break;
			case 4:
				routingPreferenceRuleGroupType = 4;
				break;
			}
			if (routingPreferenceRuleGroupType != -1)
			{
				for (int i = 0; i < routingPreferenceManager.GetNumberOfRules(routingPreferenceRuleGroupType); i++)
				{
					ElementId meppartId = routingPreferenceManager.GetRule(routingPreferenceRuleGroupType, i).MEPPartId;
					if (!(meppartId == null) && meppartId.IntegerValue >= 0)
					{
						list.Add(meppartId);
					}
				}
			}
			return list;
		}

		public static bool SetSegmentFitting(PipeType pipeType, int num, ElementId elemId, string description)
		{
			bool result = false;
			RoutingPreferenceManager routingPreferenceManager = pipeType.RoutingPreferenceManager;
			RoutingPreferenceRuleGroupType routingPreferenceRuleGroupType = -1;
			switch (num)
			{
			case 0:
				routingPreferenceRuleGroupType = 0;
				break;
			case 1:
				routingPreferenceRuleGroupType = 1;
				break;
			case 2:
				routingPreferenceRuleGroupType = 2;
				break;
			case 3:
				routingPreferenceRuleGroupType = 3;
				break;
			case 4:
				routingPreferenceRuleGroupType = 4;
				break;
			case 5:
				routingPreferenceRuleGroupType = 5;
				break;
			case 10:
				routingPreferenceRuleGroupType = 10;
				break;
			}
			if (routingPreferenceRuleGroupType != -1)
			{
				for (int i = 0; i < routingPreferenceManager.GetNumberOfRules(routingPreferenceRuleGroupType); i++)
				{
					if (elemId == routingPreferenceManager.GetRule(routingPreferenceRuleGroupType, i).MEPPartId)
					{
						routingPreferenceManager.RemoveRule(routingPreferenceRuleGroupType, i);
						break;
					}
				}
				routingPreferenceManager.AddRule(routingPreferenceRuleGroupType, new RoutingPreferenceRule(elemId, description), 0);
				result = true;
			}
			return result;
		}

		public static IList<RoutingPreferenceRule> GetSegmentRuleFitting(PipeType pipeType, int num)
		{
			RoutingPreferenceManager routingPreferenceManager = pipeType.RoutingPreferenceManager;
			RoutingPreferenceRuleGroupType routingPreferenceRuleGroupType = -1;
			switch (num)
			{
			case 0:
				routingPreferenceRuleGroupType = 0;
				break;
			case 1:
				routingPreferenceRuleGroupType = 1;
				break;
			case 2:
				routingPreferenceRuleGroupType = 2;
				break;
			case 3:
				routingPreferenceRuleGroupType = 3;
				break;
			case 4:
				routingPreferenceRuleGroupType = 4;
				break;
			}
			List<RoutingPreferenceRule> list = new List<RoutingPreferenceRule>();
			if (routingPreferenceRuleGroupType != -1)
			{
				for (int i = 0; i < routingPreferenceManager.GetNumberOfRules(routingPreferenceRuleGroupType); i++)
				{
					list.Add(routingPreferenceManager.GetRule(routingPreferenceRuleGroupType, i));
				}
			}
			return list;
		}

		public static IList<RoutingPreferenceRule> GetSegmentRuleFitting(DuctType pipeType, int num)
		{
			RoutingPreferenceManager routingPreferenceManager = pipeType.RoutingPreferenceManager;
			RoutingPreferenceRuleGroupType routingPreferenceRuleGroupType = -1;
			switch (num)
			{
			case 0:
				routingPreferenceRuleGroupType = 0;
				break;
			case 1:
				routingPreferenceRuleGroupType = 1;
				break;
			case 2:
				routingPreferenceRuleGroupType = 2;
				break;
			case 3:
				routingPreferenceRuleGroupType = 3;
				break;
			case 4:
				routingPreferenceRuleGroupType = 4;
				break;
			case 5:
				routingPreferenceRuleGroupType = 7;
				break;
			case 6:
				routingPreferenceRuleGroupType = 2;
				break;
			}
			List<RoutingPreferenceRule> list = new List<RoutingPreferenceRule>();
			if (routingPreferenceRuleGroupType != -1)
			{
				for (int i = 0; i < routingPreferenceManager.GetNumberOfRules(routingPreferenceRuleGroupType); i++)
				{
					list.Add(routingPreferenceManager.GetRule(routingPreferenceRuleGroupType, i));
				}
			}
			return list;
		}

		public static bool SetSegmentRuleFitting(PipeType pipeType, int num, IList<RoutingPreferenceRule> ruleList)
		{
			RoutingPreferenceManager routingPreferenceManager = pipeType.RoutingPreferenceManager;
			RoutingPreferenceRuleGroupType routingPreferenceRuleGroupType = -1;
			switch (num)
			{
			case 0:
				routingPreferenceRuleGroupType = 0;
				break;
			case 1:
				routingPreferenceRuleGroupType = 1;
				break;
			case 2:
				routingPreferenceRuleGroupType = 2;
				break;
			case 3:
				routingPreferenceRuleGroupType = 3;
				break;
			case 4:
				routingPreferenceRuleGroupType = 4;
				break;
			}
			if (routingPreferenceRuleGroupType != -1)
			{
				foreach (RoutingPreferenceRule routingPreferenceRule in ruleList)
				{
					routingPreferenceManager.AddRule(routingPreferenceRuleGroupType, routingPreferenceRule);
				}
			}
			return true;
		}

		public static bool SetSegmentRuleFitting(DuctType ductType, int num, IList<RoutingPreferenceRule> ruleList)
		{
			RoutingPreferenceManager routingPreferenceManager = ductType.RoutingPreferenceManager;
			RoutingPreferenceRuleGroupType routingPreferenceRuleGroupType = -1;
			switch (num)
			{
			case 0:
				routingPreferenceRuleGroupType = 0;
				break;
			case 1:
				routingPreferenceRuleGroupType = 1;
				break;
			case 2:
				routingPreferenceRuleGroupType = 2;
				break;
			case 3:
				routingPreferenceRuleGroupType = 3;
				break;
			case 4:
				routingPreferenceRuleGroupType = 4;
				break;
			case 5:
				routingPreferenceRuleGroupType = 7;
				break;
			case 6:
				routingPreferenceRuleGroupType = 2;
				break;
			}
			for (int i = routingPreferenceManager.GetNumberOfRules(routingPreferenceRuleGroupType) - 1; i >= 0; i--)
			{
				routingPreferenceManager.RemoveRule(routingPreferenceRuleGroupType, i);
			}
			if (routingPreferenceRuleGroupType != -1)
			{
				foreach (RoutingPreferenceRule routingPreferenceRule in ruleList)
				{
					routingPreferenceManager.AddRule(routingPreferenceRuleGroupType, routingPreferenceRule);
				}
			}
			return true;
		}

		public static bool DuctSetFittingElbow(DuctType ductType, FamilySymbol fs)
		{
			UnifiedModified.SetFitting(ductType.RoutingPreferenceManager, 1, fs, "盈建科弯头");
			return true;
		}

		public static bool SetViewBottomDepth(ViewPlan viewPlan, double offSet)
		{
			return false;
		}

		public static bool CheckDuctSetFittingElbow(Duct duct, string fsName)
		{
			bool result = false;
			if (UnifiedModified.CheckFittingName(duct.DuctType.RoutingPreferenceManager, 1, fsName, duct.Document))
			{
				result = true;
			}
			return result;
		}

		public static bool DuctSetFittingTee(DuctType ductType, FamilySymbol fs)
		{
			UnifiedModified.SetFitting(ductType.RoutingPreferenceManager, 2, fs, "盈建科三通");
			return true;
		}

		public static bool CheckDuctSetFittingTee(Duct duct, string fsName)
		{
			bool result = false;
			if (UnifiedModified.CheckFittingName(duct.DuctType.RoutingPreferenceManager, 2, fsName, duct.Document))
			{
				result = true;
			}
			return result;
		}

		public static bool DuctSetFittingCross(DuctType ductType, FamilySymbol fs)
		{
			UnifiedModified.SetFitting(ductType.RoutingPreferenceManager, 3, fs, "盈建科四通");
			return true;
		}

		public static bool CheckDuctSetFittingCross(Duct duct, string fsName)
		{
			bool result = false;
			if (UnifiedModified.CheckFittingName(duct.DuctType.RoutingPreferenceManager, 3, fsName, duct.Document))
			{
				result = true;
			}
			return result;
		}

		public static bool DuctSetFittingTakeOff(DuctType ductType, FamilySymbol fs)
		{
			UnifiedModified.SetFitting(ductType.RoutingPreferenceManager, 2, fs, "盈建科侧连接");
			return true;
		}

		public static bool CheckDuctSetFittingTakeOff(Duct duct, string fsName)
		{
			bool result = false;
			if (UnifiedModified.CheckFittingName(duct.DuctType.RoutingPreferenceManager, 2, fsName, duct.Document))
			{
				result = true;
			}
			return result;
		}

		public static bool DuctSetFittingTrans(DuctType ductType, FamilySymbol fs)
		{
			UnifiedModified.SetFitting(ductType.RoutingPreferenceManager, 4, fs, "盈建科变径");
			return true;
		}

		public static bool CheckDuctSetFittingTrans(Duct duct, string fsName)
		{
			bool result = false;
			if (UnifiedModified.CheckFittingName(duct.DuctType.RoutingPreferenceManager, 4, fsName, duct.Document))
			{
				result = true;
			}
			return result;
		}

		public static bool DuctSetFittingTYDF(DuctType ductType, FamilySymbol fs)
		{
			UnifiedModified.SetFitting(ductType.RoutingPreferenceManager, 7, fs, "盈建科天圆地方");
			return true;
		}

		public static bool CheckDuctSetFittingTYDF(Duct duct, string fsName)
		{
			bool result = false;
			if (UnifiedModified.CheckFittingName(duct.DuctType.RoutingPreferenceManager, 7, fsName, duct.Document))
			{
				result = true;
			}
			return result;
		}

		public static string GetMarkTagPath(string tagStyle)
		{
			string text = Product.InstallLocation + "\\MarkTagFamily\\";
			if (!(tagStyle == "pipe"))
			{
				if (!(tagStyle == "duct"))
				{
					if (tagStyle == "terminal")
					{
						text += "DTerminalTagFamily2016\\";
					}
				}
				else
				{
					text += "DuctTagFamily\\DuctTagFamily2016\\";
				}
			}
			else
			{
				text += "PipeTagFamily2016\\";
			}
			return text;
		}

		public static string GetTakeOffFittingPath()
		{
			return Product.InstallLocation + "\\MarkTagFamily\\PipingFitting\\" + "2016\\";
		}

		public static string GetMarkFamilyPath(Autodesk.Revit.DB.Document doc, string familyName)
		{
			return Path.Combine(Product.FamilyLocation, RevitVersion.GetVersionNumber(doc), "MarkTag", familyName + ".rfa");
		}

		public static Definition GetDefinition(DefinitionGroup sharedParameterGroup, string name, ParameterType type, bool visible, bool ifModify = true)
		{
			ExternalDefinitionCreationOptions externalDefinitionCreationOptions = new ExternalDefinitionCreationOptions(name, type);
			externalDefinitionCreationOptions.Visible = visible;
			externalDefinitionCreationOptions.UserModifiable = ifModify;
			return sharedParameterGroup.Definitions.Create(externalDefinitionCreationOptions);
		}

		public static Plane CreatePlane(XYZ norm, XYZ origin)
		{
			return new Plane(norm, origin);
		}

		public static NurbSpline CreateNurbSpline(IList<XYZ> controlPoints, IList<double> weights)
		{
			return NurbSpline.Create(controlPoints, weights);
		}

		public static Element CreateDirectShapeElement(Autodesk.Revit.DB.Document document, ElementId categoryId)
		{
			return DirectShape.CreateElement(document, categoryId, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
		}
	}
}
